package com.his.j259w264.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * Preventive_health_careException 异常处理
 *
 * @author 詹永泉
 * @version 1.0
 * @since 2021-09-13 15:46:39
 */

@RestControllerAdvice
public class Preventive_health_careException {

    @ExceptionHandler(SQLException.class)
    public Map<String, Object> sqlException(Throwable e) {
        Map<String, Object> map = new HashMap<>();
        e.printStackTrace();
        map.put("code", 500);
        map.put("msg", "SQL语句异常");
        return map;
    }

    @ExceptionHandler(ClassNotFoundException.class)
    public Map<String, Object> classNotFoundException(Throwable e) {
        Map<String, Object> map = new HashMap<>();
        e.printStackTrace();
        map.put("code", 500);
        map.put("msg", "没有发现数据库驱动");
        return map;
    }

    @ExceptionHandler(Throwable.class)
    public Map<String, Object> throwable(Throwable e) {
        Map<String, Object> map = new HashMap<>();
        e.printStackTrace();
        map.put("code", 500);
        map.put("msg", e.getMessage());
        return map;
    }
}

